import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import {
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
} from 'antd';
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from './TableList.less';
const FormItem = Form.Item;
@connect(({ categoryList, loading }) => ({
  categoryList,
  loading: null,
}))
@Form.create()
export default class CategoryList extends PureComponent{
	state={
		selectedRows: []
	}
	componentDidMount() {
		console.log('load category');
	    this.props.dispatch({
	      type: 'categoryList/getCategoryList',
	      payload: {
	        count: 5,
	      },
	    });
  	}
  	 renderForm() {
    const { getFieldDecorator } = this.props.form;
    return (
      <Form onSubmit={this.handleSearch} layout="inline">
        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          <Col md={8} sm={24}>
            <FormItem label="分类编号">
              {getFieldDecorator('code')(<Input placeholder="请输入" />)}
            </FormItem>
          </Col>
           <Col md={8} sm={24}>
            <FormItem label="分类名称">
              {getFieldDecorator('name')(<Input placeholder="请输入" />)}
            </FormItem>
          </Col>
          <Col md={8} sm={24}>
            <span className={styles.submitButtons}>
              <Button type="primary" htmlType="submit">
                查询
              </Button>
              <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}>
                重置
              </Button>
             
            </span>
          </Col>
        </Row>
      </Form>
    );
  }
   columns = [
    {
      title: '分类编码',
      dataIndex: 'code',
    },
    {
      title: '分类名称',
      dataIndex: 'name',
    },
    {
      title: '描述',
      dataIndex: 'desc',
      sorter: true,
      align: 'right',
    
    },   
    {
      title: '操作',
      render: (text, record) => (
        <Fragment>
          <a onClick={() => this.editCategory(true, record)}>编辑</a>
          <Divider type="vertical" />
          <a href="">订阅警报</a>
        </Fragment>
      ),
    },
  ];
  createCategory(){
    this.props.dispatch(routerRedux.push('/api/Category/Category'));
  }
  editCategory(bbb,record){
    this.props.dispatch(routerRedux.push('/api/Category/Category?id=1'));
  }
  	render(){
  		const { selectedRows} = this.state;
      debugger;
  		return (
  			 <PageHeaderWrapper title="分类">
  			 <div className={styles.tableListForm}>{this.renderForm()}</div>
          <Button icon="plus" type="primary" onClick={() => this.createCategory()}>
                新建
              </Button>
  			 <StandardTable                       
             selectedRows={selectedRows}
             data={this.props.categoryList.list}
              columns={this.columns}             
            />
  			</PageHeaderWrapper>
  			);
  	}
}